<?php
	
	//add by lin
	
	define('__ROOT__', dirname(dirname(__FILE__)));
	require_once(__ROOT__.'\models\Conn.php'); 
	require_once(__ROOT__.'\models\Member.php');
	//end add
	
class MemberController extends Controller{

	private $id;

	public function base(){
		
	}

	public function showMemberList(){
		
		$m1 = new Member();		
		$member_list = $m1->listAll();
		$arg_item = array();
		foreach( $member_list as $item )
		{
			array_push($arg_item,implode("/",$item));
		}
		$arg = implode(":",$arg_item);
		header("Location:app/views/member.php?list=$arg");
	}
	
	public function editItem(){
		$id = $this->id;
		$name = $_POST['name'];
		$profession = $_POST['profession'];
		$department = $_POST['department'];
		$tel = $_POST['tel'];
		$tax = $_POST['tax'];
		$email = $_POST['email'];
		$item = array("id"=>$id, "name"=>$name, "profession"=>$profession, "department"=>$department,
		"tel"=>$tel,"tax"=>$tax,"email"=>$email);
		$m1 = new Member();
		$m1->update($item);
		$this->showMemberList();
	}
	
	public function editPage()
	{
		$id = $this->id;
		//根据这个id值从数据库里获取相应的数据记录，这边暂时假设根据这个id获得到了数据，如下
		$m1 = new Member();
		$item = $m1->getById($id);
		//var_dump($item);die;		
		//print_r($item);
		$arg = implode(":",$item);
		header("Location:app/views/edit_member.php?item=$arg");
	}
	
	public function deleteItem()
	{
		var_dump('delete');
		$id = $this->id;
		//根据这个id值从数据库里删除一条记录
		
		$m1 = new Member();
		$m1->delete($id);
		
		$this->showMemberList();
	}
	
	public function addItemPage()
	{
		header("Location:app/views/add_member.php");
	}
	
	//没改
	public function addItem()
	{
		$new_item_area = $_POST['area'];
		$new_item_time = $_POST['time'];
		$new_item_indicator = $_POST['indicator'];
		$new_item_value = $_POST['value'];
		$new_item_p5 = $_POST['p5'];
		
		//根据以上的值在数据库插入一条新记录
		$item = array("area"=>$new_item_area,"time"=>$new_item_time,"indicator"=>$new_item_indicator,"value"=>$new_item_value,"p5"=>$new_item_p5);
		//add by lin
		$r1 = new Resources();
		$r1->insert($item);
		$this->showEconomyList();
	}
	
	// public function showEcologyList(){
		
		// header("Location:app/views/ecology.php");
	// }
	
	// public function showSocietyList(){
	
		// header("Location:app/views/society.php");
	// }

	public function setParams($params)
	{
		$this->id = $params[0];
	}
}
